package com.microcdyUser.controller;
import com.microcdy.sys.pojo.SysRoleMenu;
import com.microcdyUser.service.SysRoleMenuService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:cdy
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sysRoleMenu")
@CrossOrigin
public class SysRoleMenuController {

    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    /***
     * SysRoleMenu分页条件搜索实现
     * @param sysRoleMenu
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  SysRoleMenu sysRoleMenu, @PathVariable  int page, @PathVariable  int size){
        //调用SysRoleMenuService实现分页条件查询SysRoleMenu
        PageInfo<SysRoleMenu> pageInfo = sysRoleMenuService.findPage(sysRoleMenu, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SysRoleMenu分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SysRoleMenuService实现分页查询SysRoleMenu
        PageInfo<SysRoleMenu> pageInfo = sysRoleMenuService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sysRoleMenu
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<SysRoleMenu>> findList(@RequestBody(required = false)  SysRoleMenu sysRoleMenu){
        //调用SysRoleMenuService实现条件查询SysRoleMenu
        List<SysRoleMenu> list = sysRoleMenuService.findList(sysRoleMenu);
        return new Result<List<SysRoleMenu>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用SysRoleMenuService实现根据主键删除
        sysRoleMenuService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SysRoleMenu数据
     * @param sysRoleMenu
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  SysRoleMenu sysRoleMenu,@PathVariable Long id){
        //设置主键值
        sysRoleMenu.setRoleId(id);
        //调用SysRoleMenuService实现修改SysRoleMenu
        sysRoleMenuService.update(sysRoleMenu);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SysRoleMenu数据
     * @param sysRoleMenu
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   SysRoleMenu sysRoleMenu){
        //调用SysRoleMenuService实现添加SysRoleMenu
        sysRoleMenuService.add(sysRoleMenu);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SysRoleMenu数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SysRoleMenu> findById(@PathVariable Long id){
        //调用SysRoleMenuService实现根据主键查询SysRoleMenu
        SysRoleMenu sysRoleMenu = sysRoleMenuService.findById(id);
        return new Result<SysRoleMenu>(true,StatusCode.OK,"查询成功",sysRoleMenu);
    }

    /***
     * 查询SysRoleMenu全部数据
     * @return
     */
    @GetMapping
    public Result<List<SysRoleMenu>> findAll(){
        //调用SysRoleMenuService实现查询所有SysRoleMenu
        List<SysRoleMenu> list = sysRoleMenuService.findAll();
        return new Result<List<SysRoleMenu>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
